package util;

import java.util.Vector;

/**
 * Functions related to Vector Math or Math in general.
 * 
 * @author Dan Avila
 *
 */
public class VectorMath {

	/**
	 * Returns the Euclidian distance between two vectors.
	 * Assumes they are of equal dimensionality.
	 * 
	 * @param a - the first vector
	 * @param b - the second vector
	 * @return the distance between the two points
	 */
	public static double euclidianDistance(Vector<Double> a, Vector<Double> b){
		double total = 0;
		
		for(int i = 0;i<a.size();i++){
			total+=StrictMath.pow(a.get(i).doubleValue()-b.get(i).doubleValue(), 2.0);
		}
		
		return StrictMath.sqrt(total);
	}
	/**
	 * Adds the second vector to the first.
	 * 
	 * @param a - the vector that b will be added to
	 * @param b - the vector that will be added to a
	 */
	public static void add(Vector<Double> a, Vector<Double> b)
	{
		for(int i = 0; i<a.size();i++)
		{
			a.set(i, a.get(i)+b.get(i));
		}
	}
	
	public static double factorial(int num)
	{
		double val = 1.0;
		
		for(int i = 1; i <= num;i++)
		{
			val*=i;
		}
		
		return val;
	}
	
}
